Basic understanding of skip help request

Hi,

Okay, I'm not understanding something and not sure what it is.

Background, using global skip lists to contain information. There are four parallel skips, each supposed to have twelve entries, one entry per month. The code is propriety, read I can't post it but would if I could.

Two questions arose.

Q1: The original developer returns a skip list from a sub. The skip is created in that sub and returned. He/She did this because the caller uses the return to assign to a local skip variable in the calling routine. At first glance this seems like bad style (i.e. allocating memory in a sub that is passed back). It works but I'm sure it leaks. I'm thinking each time the sub is called the create function will allocate a 'new' skip. The skip is then populated with twelve items. Shouldn't this be done a different way? Any suggestions on how it should be done(maybe pass a skip in that was created in the caller) would be greatly appreciated. I hope some of that made sense.

Q2: I created global skips to use where I'm adding modifications to the code, but I have problems clearing the skip and I can't figure it out. My first approach was to loop through the twelve elements if the skip and set the value parts to zero (it didn't work right, everything was coming out zero all time). What did work was that in the place I was looping through the skip I replaced that with deleting and recreating the skips. Why would that work and not looping?

Best,
Frank
lanef - Tue Mar 26 08:32:53 EDT 2013

Re: Basic understanding of skip help request
llandale - Tue Mar 26 14:09:24 EDT 2013

Sorry this is formatted odd, I did "preview" but could not fix it.

[1] There is nothing wrong with this:

Skip skpGlobal = null
 
Skip  MakeIt(whatever)
{     // caller should indeed 'delete' the returned Skip when finished.
  Skip skp = createString()
  put(skp, "January", something)
   ...
  put(skp, "Decemeber", something)
  return(skp)
}
 
void Whatever()
{
  skpGlobal = MakeIt(whatever)
  deal with it
  delete(skpGlobal)
}
// Not much different:
void MakeIt(whatever, &Skip skp)

 


The Skip is "allocated" globally even if the call is in a function. This does NOT work for generic "array"s (e.g. string Months[12]), since they are allocated locally and fundamentally corrupted when the function ends. Other than "array"s (lower case "a"), I think all other structures are OK to create in a function, specifically including an "Array" (upper case "A").

[2] You can "clear" a Skip like this; but you need to know the KEY "type"

 

 

int Data   // I don't know the type of Data, but it doesn't matter
string Key
for Data in skp do
{  Key = (string key skp)
   delete(skp, Key)   // Remove this KEY from the Skip
}


or of course:

 

 

delete(skp)
skp = createString()


I wonder however, if you just want to replace individual data

 

 

  • delete(skp, "January")
  • put(skp, "January", "New Information")

I think there is an undocumented Skip "replace" perm:

 

 

  • put(skp, "January", "New Information", true).


[3] In your case it's clear to me the "Key" of your skip's needs to be either 'string' months (e.g. "January") or 'int' month number (e.g. 1).

-Louie

 

Re: Basic understanding of skip help request
lanef - Tue Mar 26 14:14:51 EDT 2013

llandale - Tue Mar 26 14:09:24 EDT 2013

Sorry this is formatted odd, I did "preview" but could not fix it.

[1] There is nothing wrong with this:

Skip skpGlobal = null
 
Skip  MakeIt(whatever)
{     // caller should indeed 'delete' the returned Skip when finished.
  Skip skp = createString()
  put(skp, "January", something)
   ...
  put(skp, "Decemeber", something)
  return(skp)
}
 
void Whatever()
{
  skpGlobal = MakeIt(whatever)
  deal with it
  delete(skpGlobal)
}
// Not much different:
void MakeIt(whatever, &Skip skp)

 


The Skip is "allocated" globally even if the call is in a function. This does NOT work for generic "array"s (e.g. string Months[12]), since they are allocated locally and fundamentally corrupted when the function ends. Other than "array"s (lower case "a"), I think all other structures are OK to create in a function, specifically including an "Array" (upper case "A").

[2] You can "clear" a Skip like this; but you need to know the KEY "type"

 

 

int Data   // I don't know the type of Data, but it doesn't matter
string Key
for Data in skp do
{  Key = (string key skp)
   delete(skp, Key)   // Remove this KEY from the Skip
}


or of course:

 

 

delete(skp)
skp = createString()


I wonder however, if you just want to replace individual data

 

 

  • delete(skp, "January")
  • put(skp, "January", "New Information")

I think there is an undocumented Skip "replace" perm:

 

 

  • put(skp, "January", "New Information", true).


[3] In your case it's clear to me the "Key" of your skip's needs to be either 'string' months (e.g. "January") or 'int' month number (e.g. 1).

-Louie

 

Thank you Louie!

I'm going to have to study this a bit and write some test programs.

Best,
Frank

Re: Basic understanding of skip help request
SystemAdmin - Wed Mar 27 12:16:00 EDT 2013

llandale - Tue Mar 26 14:09:24 EDT 2013

Sorry this is formatted odd, I did "preview" but could not fix it.

[1] There is nothing wrong with this:

Skip skpGlobal = null
 
Skip  MakeIt(whatever)
{     // caller should indeed 'delete' the returned Skip when finished.
  Skip skp = createString()
  put(skp, "January", something)
   ...
  put(skp, "Decemeber", something)
  return(skp)
}
 
void Whatever()
{
  skpGlobal = MakeIt(whatever)
  deal with it
  delete(skpGlobal)
}
// Not much different:
void MakeIt(whatever, &Skip skp)

 


The Skip is "allocated" globally even if the call is in a function. This does NOT work for generic "array"s (e.g. string Months[12]), since they are allocated locally and fundamentally corrupted when the function ends. Other than "array"s (lower case "a"), I think all other structures are OK to create in a function, specifically including an "Array" (upper case "A").

[2] You can "clear" a Skip like this; but you need to know the KEY "type"

 

 

int Data   // I don't know the type of Data, but it doesn't matter
string Key
for Data in skp do
{  Key = (string key skp)
   delete(skp, Key)   // Remove this KEY from the Skip
}


or of course:

 

 

delete(skp)
skp = createString()


I wonder however, if you just want to replace individual data

 

 

  • delete(skp, "January")
  • put(skp, "January", "New Information")

I think there is an undocumented Skip "replace" perm:

 

 

  • put(skp, "January", "New Information", true).


[3] In your case it's clear to me the "Key" of your skip's needs to be either 'string' months (e.g. "January") or 'int' month number (e.g. 1).

-Louie

 

llandale - "The Skip is "allocated" globally even if the call is in a function." if that was true shouldn't the following code work?

 

 

Skip List1 = create ()
put(List1, 0, "List1")
void main()
{
    Skip List2 = create ()
        put(List2, 0, "List2")
        
        string temp = null
        for temp in List2 do {
                string temp = null
                for temp in List2 do {
                        print temp "\n"
                }
        }
}
 
main()
 
string temp = null
for temp in List1 do {
        string temp = null
        for temp in List1 do {
                print temp "\n"
        }
}
 
// DXL error
temp = null
for temp in List2 do {
        string temp = null
        for temp in List2 do {
                print temp "\n"
        }
}



-Jim



 

 

Re: Basic understanding of skip help request
llandale - Wed Mar 27 15:55:11 EDT 2013

SystemAdmin - Wed Mar 27 12:16:00 EDT 2013

llandale - "The Skip is "allocated" globally even if the call is in a function." if that was true shouldn't the following code work?

 

 

Skip List1 = create ()
put(List1, 0, "List1")
void main()
{
    Skip List2 = create ()
        put(List2, 0, "List2")
        
        string temp = null
        for temp in List2 do {
                string temp = null
                for temp in List2 do {
                        print temp "\n"
                }
        }
}
 
main()
 
string temp = null
for temp in List1 do {
        string temp = null
        for temp in List1 do {
                print temp "\n"
        }
}
 
// DXL error
temp = null
for temp in List2 do {
        string temp = null
        for temp in List2 do {
                print temp "\n"
        }
}



-Jim



 

 

If we put two things in each Skip, this works:

Skip List1 = create ()
put(List1, 0, "List1-0")
put(List1, 1, "List1-1")
void main()
{
    Skip List2 = create ()
        put(List2, 0, "List2-0")
        put(List2, 1, "List2-1")
        
        string temp = null
        for temp in List2 do {
                string temp1 = null
                for temp1 in List2 do {
                        print temp1 "\n"
                }
        }
}
 
main()
 
string temp = null
for temp in List1 do {
        string temp = null
        for temp in List1 do {
                print temp "\n"
        }
}


Now I say that the "Allocation" is global. Since main() does not delete Skip List2, there is an Allocation Unit assigned that can never be freed and will occupy memory for the life of the program; specifically it is NOT freed just because main() ended.

I did not suggest that variable "List2" becomes global, that variable is still local and of course the bottom part of your code is referencing and "undeclared variable".

-Louie

Re: Basic understanding of skip help request
llandale - Wed Mar 27 15:57:44 EDT 2013

llandale - Wed Mar 27 15:55:11 EDT 2013

If we put two things in each Skip, this works:

Skip List1 = create ()
put(List1, 0, "List1-0")
put(List1, 1, "List1-1")
void main()
{
    Skip List2 = create ()
        put(List2, 0, "List2-0")
        put(List2, 1, "List2-1")
        
        string temp = null
        for temp in List2 do {
                string temp1 = null
                for temp1 in List2 do {
                        print temp1 "\n"
                }
        }
}
 
main()
 
string temp = null
for temp in List1 do {
        string temp = null
        for temp in List1 do {
                print temp "\n"
        }
}


Now I say that the "Allocation" is global. Since main() does not delete Skip List2, there is an Allocation Unit assigned that can never be freed and will occupy memory for the life of the program; specifically it is NOT freed just because main() ended.

I did not suggest that variable "List2" becomes global, that variable is still local and of course the bottom part of your code is referencing and "undeclared variable".

-Louie

..err.. "never" because main() sets no global variable pointing to the skip. If "List2" was declared globally then of course you could delete the Skip later. Ditto if you put that Skip into some other Skip, of found some way to get a handle on it.

-Louie